package cn.cy.web;

import cn.cy.pojo.BizCheckResult;
import cn.cy.pojo.BizClaimVoucher;
import cn.cy.pojo.ClaimVoicherCondition;
import cn.cy.pojo.ClaimVoucherDetail;
import cn.cy.service.BizClaimVoucherService;
import cn.cy.service.CheckResultservice;
import cn.cy.service.ClaimVoucherDetailService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;
@Controller("claimVoucherDetailAction")
public class ClaimVoucherDetailAction extends ActionSupport {
    private  static final Logger log  = Logger.getLogger(ClaimVoucherDetailAction.class);
    @Autowired
    private BizClaimVoucherService claimVoucherService;
    @Autowired
    private ClaimVoucherDetailService claimVoucherDetailService;
    @Autowired
    private CheckResultservice checkResultservice;
    //添加，查看，修改
    private BizClaimVoucher claimVoucher;

    //条件查询
    private ClaimVoicherCondition claimVoicherCondition;
    //查询报销单
    public String Show(){
        if(claimVoicherCondition == null){
            claimVoicherCondition = new ClaimVoicherCondition();
        }
        Map<String,Object> request = (Map)ActionContext.getContext().get("request");
        Integer pageNo = 1;
        if(request.get("pageNo") != null && !request.get("pageNo").equals("")){
            pageNo = Integer.parseInt(request.get("pageNo").toString());
            if(pageNo != null && pageNo > 0){
                claimVoicherCondition.setCurrPageNo(pageNo);
            }
        }
        claimVoicherCondition.setCurrPageNo(pageNo);
        claimVoicherCondition.setTotalCount(claimVoucherService.count());
        log.info(claimVoicherCondition);
        List<BizClaimVoucher> list = claimVoucherService.finddByStatusAndDate(claimVoicherCondition);
        log.info("list------"+list.toString());
        request.put("claimVouchers",list);
        claimVoicherCondition.setTotalCount(Long.parseLong(list.size()+""));
        List<String> statusList = claimVoucherService.findStatusAll();
        request.put("statusMap",statusList);
        return SUCCESS;
    }

    public String update(){
        return "";
    }


    public String View(){
        Map<String,Object> request = (Map)ActionContext.getContext().get("request");
        //查询一条报销记录
        claimVoucher = claimVoucherService.finfById(claimVoucher.getId());
        //查询报销的明细
        List<ClaimVoucherDetail> claimVoucherDetail = claimVoucherDetailService.findById(claimVoucher.getId());
        List<BizCheckResult> checkResultList = checkResultservice.findByClaimId(claimVoucher.getId());
        request.put("claimVoucher",claimVoucher);
        request.put("claimVoucherDetail",claimVoucherDetail);
        request.put("checkResultList",checkResultList);
        return "view";
    }

    public String add(){

        return SUCCESS;
    }



    public BizClaimVoucher getClaimVoucher() {
        return claimVoucher;
    }

    public void setClaimVoucher(BizClaimVoucher claimVoucher) {
        this.claimVoucher = claimVoucher;
    }

    public ClaimVoicherCondition getClaimVoicherCondition() {
        return claimVoicherCondition;
    }

    public void setClaimVoicherCondition(ClaimVoicherCondition claimVoicherCondition) {
        this.claimVoicherCondition = claimVoicherCondition;
    }
}
